﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System;
using System.Collections.Generic;
using System.Linq;



class Sol46
{

    IList<IList<int>> res;
    public IList<IList<int>> Permute(int[] nums)
    {
        res = new List<IList<int>>();

        //for (int i = 0; i < nums.Length; i++)
        //{
        //    bool[] visted= new bool[nums.Length];

        //    IList<int> path = new List<int>();
        //    DFS(nums, path, 0, visted);

        //}
        bool[] visted = new bool[nums.Length];

        IList<int> path = new List<int>();
        DFS(nums, path,  visted);

        return res;
    }

    void DFS(int[] nums, IList<int> path, bool[] visted)
    {


        if (path.Count == nums.Length)
        {

            res.Add(new List<int>(path));
            return;
        }

        for (int i = 0; i < nums.Length; i++)
        {
            if(!visted[i]) {
                path.Add(nums[i]);
                visted[i] = true;

                DFS(nums, path, visted);
                
                path.RemoveAt(path.Count - 1);

                visted[i] = false;
            }
        }


    }
}

class Program46
{
    static void Main46(string[] args)
    {
        // To read from standard input, use following statements.
        /*
        String line;
        while ((line = Console.ReadLine()) != null)
        {
            Console.WriteLine(line);
        }
        */
    

        Sol46 sol = new ();
        int[] nums = { 1, 2, 3 };
        IList<IList<int>> res= sol.Permute(nums);

        for(int i = 0;i < res.Count;i++) { 
        
            for(int j = 0;j < nums.Length;j++)
            {
                Console.Write(res[i][j]+",");

            }

            Console.WriteLine();
        }


    }
}
